<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
</head>
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/ui/Input.css">
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/ui/Placeholder.css">
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/ui/Button.css">
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/animate.css">
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/ui.css">
<link rel="stylesheet" href="/css/mockup.css">
<script src="https://qidian.gtimg.com/c/=/lulu/theme/pure/js/common/ui/Follow.js,/lulu/theme/pure/js/common/ui/ErrorTip.js,/lulu/theme/pure/js/common/ui/Validate.js"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/ui/Button.css">
<link rel="stylesheet" href="https://qidian.gtimg.com/lulu/pure/css/common/ui/Dialog.css">
<script src="https://qidian.gtimg.com/lulu/pure/js/common/ui/Dialog.js"></script>
<style>
    .div-input{
        margin-top: 1%;
        margin-left: 20%;
    }
</style>
<body>
<h3 align="center" style="color: #f59b00">欢迎注册平台账号</h3>
    <form  action="/user/insert" method="post" id="form" style="margin-top: 10%;margin-left:20%;width: 60%">
        <div class="div-input">
            <label class="left f14" >用名</label>
            <input type="text"  class="ui-input" size="50" name="name" required>
        </div>
        <div class="div-input">
            <label class="left f14" >密码</label>
            <input type="password"  class="ui-input" size="50" name="passWord" required>
        </div>
        <!--    <div class="div-input">-->
        <!--        <label class="left f14" >资产</label>-->
        <!--        <input type="number"  class="ui-input" size="18" name="fund" required>-->
        <!--    </div>-->
        <div class="div-input"  >
            <button type="button" onclick="send('/user/insert','/login')" class="ui-button" data-type="primary">注册</button>
        </div>
    </form>


</body>

<script>

    function send() {
        //创建异步对象
        var xhr = new XMLHttpRequest();
        //设置请求的类型及url
        xhr.open('post', '/user/insert',true);
        //post请求一定要添加请求头才行不然会报错
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        //发送请求
        var data = $("#form").serialize();
        // FirstName=Bill&LastName=Gates
        console.log(data);
        xhr.send(data);
        xhr.onreadystatechange = function () {
            // 这步为判断服务器是否正确响应
            if (xhr.readyState == 4 && xhr.status == 200) {
                // console.log(xhr.responseText);
                var re = JSON.parse(xhr.responseText);
                if(re.code == 200 ){
                    new Dialog().alert('操作成功！', {
                        type: 'success'
                    });
                    setTimeout(jump,2000);
                }else{
                    new Dialog().alert(re.msg+"!", {
                        type: 'failure'
                    });
                }
            }
        };
    }
    function jump() {
        window.location = "/login"
    }



</script>

</html>